package com.qianfeng.openapi.search.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/12/28
 * @Time: 下午5:27
 */
@Configuration
@EnableSwagger2
//localhost:8001/swagger-ui.html
public class SwaggerConfig {

    @Value("${swagger.title}")
    private String title;//标题

    @Value("${swagger.description}")
    private String description;//描述

    @Value("${swagger.version}")
    private String version;//版本
    @Value("${swagger.contact}")
    private String contact;//email
    @Value("${swagger.basePackage}") //controller所在的包
    private  String basePackage;


    @Bean
    public Docket docket(){

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).
                select().apis(RequestHandlerSelectors.basePackage(basePackage)).build();

    }

    @Bean
    public ApiInfo apiInfo(){
        //(String title, String description, String version, String termsOfServiceUrl, Contact contact, String license, String licenseUrl,
        // Collection<VendorExtension > vendorExtensions
        //return  new ApiInfo(title,description,version,null,new Contact("qf","www.1000phone.com",contact),"","",null);

        return new ApiInfoBuilder().contact(new Contact("qf","www.1000phone.com",contact)).
                version(version).title(title).description(description).build();
    }


}
